package heartsinjava2;

import java.util.*;
import javax.swing.*;


public final class Deck {

    

    private static final Deck prototype = new Deck(true);
    private  final Stack<Card> cards = new Stack<Card>();
    private final String directory = "D:\\cards\\";
    private int index;

    private Deck(boolean dummy) {
        for (Suit suit : Suit.values()) {
            for (Rank rank : Rank.values()) {
                String imageFile = directory + Card.getFilename( suit, rank );
                ImageIcon cardImage = new ImageIcon(imageFile);
                this.cards.push(new Card(suit, rank, cardImage));
            }
        }
    }

    public Deck() {
        this.cards.addAll(Deck.prototype.cards);
        index = 0;
    }

    public void shuffle(Random rng) {
        final ArrayList<Card> tempCards = new ArrayList<Card>(this.cards);
        this.cards.clear();

        while (tempCards.size() > 0) {
            int Index = rng.nextInt(tempCards.size());
            this.cards.push(tempCards.remove(Index));
        }
    }

    public Card draw() {
        ++index;
        return this.cards.pop();

    }

    public Card[] draw(int count) {
        final Card[] results = new Card[count];

        for (int Index = 0; Index < count; Index++) {
            results[Index] = this.cards.pop();
        }

        return results;
    }

    public boolean isEmpty() {
        return this.cards.size() == 0;
    }

    public int size() {
        return this.cards.size();
    }



}